import os
import json
def ReadTxt(path):
    f = open(path, "r")
    str = f.read()
    f.close()
    return str
desktop = []
if not os.path.exists("/usr/share/applications"):
    print(json.dumps([]))
for i in os.listdir("/usr/share/applications"):
    try:
        lowerI = ReadTxt("/usr/share/applications/" + i).lower()
    except:
        continue
    line = False
    if "name[zh_cn]=" in lowerI:
        line = True
    temp = [None, None]
    if "NoDisplay=true".lower() in lowerI.replace(" ", "") or "Terminal=true".lower() in lowerI.replace(" ", ""):
        continue
    for i in lowerI.splitlines():
        if ["name=", "name[zh_cn]="][int(line)] in i:
            if not temp[0] == None:
                continue
            temp[0] = (i[i.find("=") + 1:])
        if "exec=" in i:
            if not temp[1] == None:
                continue
            temp[1] = (i[i.find("=") + 1:])
    if temp == [None, None]:
        continue
    desktop.append(temp)
print(json.dumps(desktop))